package com.hxd.otc.dialog;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.flyco.dialog.widget.base.BaseDialog;
import com.hxd.otc.R;
import com.hxd.otc.utils.AddressUtil;
import com.hxd.otc.utils.CommonUtil;
import com.hxd.otc.utils.ResourceUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by lzy on 2018/12/20 0020.
 * description ${分享链接}
 */
public class ShareLinkDialog extends BaseDialog<ShareLinkDialog> {
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.iv_close)
    ImageView mIvClose;
    @BindView(R.id.tv_recommended_download_link)
    TextView mTvRecommendedDownloadLink;
    @BindView(R.id.tv_content)
    TextView mTvContent;
    @BindView(R.id.tv_paste)
    TextView mTvPaste;
    @BindView(R.id.iv_copy_success)
    ImageView mIvCopySuccess;

    private String mLink;
    private String mTitle;
    private String mContent;
    private boolean mIsShowContent = true;
    private boolean mIsShowLink = true;
    private boolean mIsShowCopySuccessIcon = true;
    private String mConfirmText;
    private boolean mIsCopyLink;

    public ShareLinkDialog(Context context) {
        super(context);
    }

    @Override
    public View onCreateView() {
        widthScale(0.8f);
        return View.inflate(getContext(), R.layout.dialog_share_link, null);
    }

    @Override
    public void onViewCreated(View view) {
        ButterKnife.bind(this, view);
    }

    @Override
    public void setUiBeforShow() {
        mTvTitle.setText(mTitle);
        mTvContent.setText(mContent);
        mTvRecommendedDownloadLink.setText(mLink);
        mTvPaste.setText(mConfirmText);

        mTvContent.setVisibility(mIsShowContent ? View.VISIBLE : View.GONE);
        mTvRecommendedDownloadLink.setVisibility(mIsShowLink ? View.VISIBLE : View.GONE);
        mIvCopySuccess.setVisibility(mIsShowCopySuccessIcon ? View.VISIBLE : View.GONE);
    }

    public ShareLinkDialog setLink(String link) {
        mLink = link;
        return this;
    }

    public ShareLinkDialog setTitle(String title) {
        mTitle = title;
        return this;
    }

    public ShareLinkDialog setContent(String content) {
        mContent = content;
        return this;
    }

    public ShareLinkDialog setConfirmText(String confirmText) {
        mConfirmText = confirmText;
        return this;
    }

    public ShareLinkDialog isShowContent(boolean isShowContent) {
        mIsShowContent = isShowContent;
        return this;
    }

    public ShareLinkDialog isShowLink(boolean isShowLink) {
        mIsShowLink = isShowLink;
        return this;
    }

    public ShareLinkDialog isShowCopySuccessIcon(boolean isShowCopySuccessIcon) {
        mIsShowCopySuccessIcon = isShowCopySuccessIcon;
        return this;
    }

    public ShareLinkDialog isCopyLink(boolean isCopyLink) {
        mIsCopyLink = isCopyLink;
        return this;
    }


    @OnClick({R.id.iv_close, R.id.tv_paste})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_close:
                dismiss();
                break;
            case R.id.tv_paste:
                if (mIsCopyLink) {
                    AddressUtil.copyAddress(getContext(), ResourceUtil.getString(R.string.share_model, mLink), "");
                }
                CommonUtil.startWeChat(getContext());
                dismiss();
                break;
        }
    }
}
